<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
set_html('title','订单详情');
if($_RQ['op']=='main'){
	if(!$_RQ['id'] && !$_RQ['orderid']){
		exi('请选择订单！','error');
	}
	if($_RQ['id']){
		$commission=$this->get('commission',array('id'=>$_RQ['id']));
		$item=$this->get('order',array('ordersn'=>$commission['ordersn']));
	}
	if($_RQ['orderid']){
		$item=$this->get('order',array('id'=>$_RQ['orderid']));
		$commission['mid']=$item['mid'];
	}
	$order=pdo_get('jy_weishop_order',array('ordersn'=>$item['ordersn']));
	$item['money']=$commission['money'];
	$item['price']=$order['price'];
	$item['paytime']=$order['paytime'];
	$item['finishtime']=$order['finishtime'];
	$item['status']=$order['status'];
		$item['member']=model('core/member')->basic($commission['mid']);
		$item['statustitle']=$this->commission_status[$commission['status']];	
		$item['typetitle']=$this->commission_money_types[$commission['level']];
		$ordergoods=pdo_getall('jy_weishop_order_goods',array('orderid'=>$order['id'],'uniacid'=>$_SESSION['uniacid']),array('goodsid','optionid','price','total','goodssn','productsn'));
		$merchs =array();
		$item['feemoney']=0;
		foreach($ordergoods as &$gv){
			$goodsinfo = pdo_get('jy_weishop_goods',array('id'=>$gv['goodsid'],'uniacid'=>$_SESSION['uniacid']),array('id','marketprice','unit','image','title','merchid'));
			$goodsinfo['total']=$gv['total'];
			$goodsinfo['price']=$gv['price'];
			if($_SESSION['is_tomedia']){
			$goodsinfo['image']=$goodsinfo['image']?tomedia($goodsinfo['image']):'';
			}
			$goodsinfo['weight']=pdo_getcolumn('jy_weishop_goods_dispatch',array('goodsid'=>$gv['goodsid']),'weight');
			if($feemoneyset['isopen']==1){
				$gv['feemoney']=$goodsinfo['marketprice']>0?$goodsinfo['marketprice']-$item['price']:$feemoneyset['feerade']*$item['price']/100;
				$gv['feemoney']=$gv['total']*$gv['feemoney'];
				$item['feemoney'] +=$gv['feemoney'];
				$goodsinfo['feemoney']=price($gv['feemoney']);
			}
			//获取门店
			$stores = array();
			$goodsinfo['storeids'] = json_decode($goodsinfo['storeids'],true);
			if ($goodsinfo['isverify'] == 1) {
				if (empty($goodsinfo['storeids'])) {
					$stores = pdo_getall('jy_weishop_store',array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'type'=>array(2,3)));
				}else {
					foreach($goodsinfo['storeids'] as $sv){
						$stores[]= pdo_get('jy_weishop_store',array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'type'=>array(2,3),'id'=>$sv['id']));
					}
				}
			}elseif($shopset['openstore'] ==1){
				if (empty($goodsinfo['storeids'])) {
					$stores = pdo_getall('jy_weishop_store',array('uniacid'=>$_SESSION['uniacid'],'status'=>1));
				}else {
					foreach($goodsinfo['storeids'] as $sv){
						$stores[]= pdo_get('jy_weishop_store',array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'id'=>$sv['id']));
					}
				}
			}
			$goodsinfo['store']=$stores;
			//商品规格
			if($gv['optionid']){
				$specs=pdo_getcolumn('jy_weishop_goods_option',array('id'=>$gv['optionid']),'specs');
				$specs=explode("_",$specs);
				foreach($specs as &$spec){
					$spec=pdo_getcolumn('jy_weishop_goods_spec_item',array('id'=>$spec),'title');
				}
				$goodsinfo['selespename']=implode("，",$specs);
			}
			//获取商户
			if($goodsinfo['merchid']){
				if(!$merchs[$goodsinfo['merchid']]){
					$merchinfo = pdo_get('jy_merch_user',array('id'=>$goodsinfo['merchid'],'uniacid'=>$_SESSION['uniacid']));
					$merchs[$goodsinfo['merchid']] = $merchinfo;
				}
				$merchs[$goodsinfo['merchid']]['goods'][] = $goodsinfo;
			}else{
				$merchs[0]['goods'][] = $goodsinfo;
			}
	}
	$item['createtime']=date('Y/m/d H:i:s',$item['createtime']);
	$item['paytime']=date('Y/m/d H:i:s',$item['paytime']);
	$item['finishtime']=date('Y/m/d H:i:s',$item['finishtime']);
	$item['merchs']=$merchs;
	$return['order']=$item;
	exi($return);
}
?>